#include<stdio.h>
#include<stdlib.h>

int rand_m_1(int n, int m)
{
	int i, s = m, r = n;
	for (i = 0; i < n; i++) {
		if ((rand() % r) < s) {
			printf("%d ", i);
			s--;
		}
		r--;
	}
	printf("\n");
}

static int cmp(const void *p1, const void *p2)
{
	return *(const int *)p1 - *(const int *)p2;
}

int rand_m_2(int n, int m)
{
	int i, arr[n];
	
	for (i = 0; i < n; i++)
		arr[i] = i;
	for (i = 0; i < m; i++) {
		int j, tmp;
		j = rand() % n;
		tmp = arr[i];
		arr[i] = arr[j];
		arr[j] = tmp;
	}
	qsort(arr, m, sizeof(int), cmp);
	for (i = 0; i < m; i++)
		printf("%d ", arr[i]);
	printf("\n");
}

int main() {
	rand_m_1(50, 5);
	rand_m_2(50, 5);
	return 0;
}

